//
//  CounselingIformationButtonCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/23.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "CounselingIformationButtonCell.h"

@implementation CounselingIformationButtonCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.baseView];
    _baseView.frame = CGRectMake(100, 0, APP_WIDTH, 40);
    CGFloat X = (self.frame.size.width - 200)/8;
    for (int i = 0; i<8; i++) {
        if (i<6) {
            UILabel *label = [[UILabel alloc]init];
            label.text = @"测试";
            label.textAlignment = 1;
            label.font = [UIFont systemFontOfSize:13];
            label.textColor = TITLECOLOR;
            label.tag = 1+i;
            [_baseView addSubview:label];
            label.frame = CGRectMake(X*i, 10, X, 20);
        }else{
            if (i == 6) {
                
                [_baseView addSubview:self.lookButton];
                _lookButton.frame = CGRectMake(X*6+60, 10, 16, 21);
            }else{
                
                [_baseView addSubview:self.videoButton];
                _videoButton.frame = CGRectMake(X*7+60, 10,16, 21);
            }
        }
        
    }
}
//CGFloat X = (self.frame.size.width - 200)/8;
//CGFloat W = X-12;
//for (int i = 0; i<8; i++) {
//    UILabel *label = (UILabel *)[_baseView viewWithTag:i+1];
//    if (i == 0) {
//        label.frame = CGRectMake(0, 10, X/1.8, 20);
//    }else if(i == 1){
//        label.frame = CGRectMake(X/1.8, 10, 1.5*X, 20);
//    }else if (i == 2){
//        label.frame = CGRectMake(X/1.8+X*1.5, 10, 2*X, 20);
//    }else{
//        label.frame = CGRectMake(X/1.8+X*3.5+W*(i-3), 10, W, 20);
//    }
//    label.text = self.nameArray[i];
//}
- (void)reloadViewLayout{
    CGFloat X = (self.frame.size.width - 200)/8;
    CGFloat W = X-12;
    
    //TOP
//    SYDataTutorModel *tutorModel = self.nameArray[self.indexPath.row-1];
//    for (int i = 0; i<8; i++) {
//        UILabel *label = (UILabel *)[_baseView viewWithTag:i+1];
//        if (i == 0) {
//            label.text = tutorModel.lessonTimes;
//            label.frame = CGRectMake(0, 10, X/1.8, 20);
//        }else if(i == 1){
//            label.text = tutorModel.beginDate;
//            label.frame = CGRectMake(X/1.8, 10, 1.5*X, 20);
//        }else if (i == 2){
//            label.text = tutorModel.endDate;
//            label.frame = CGRectMake(X/1.8+X*1.5, 10, 2*X, 20);
//        }else{
//            if (i == 6) {
//                _lookButton.frame = CGRectMake(X/1.8+X*3.5+W*(i-3)+W/2-8, 10,16, 20);
//            }else if (i == 7){
//                _videoButton.frame = CGRectMake(X/1.8+X*3.5+W*(i-3)+W/2-8, 10, 16, 20);
//            }else{
//
//                if (i == 3) {
//                    label.text = tutorModel.duration;
//                } else if (i == 4) {
//                    label.text = tutorModel.statusName;
//                } else if (i == 5) {
//                    label.text = [NSString stringWithFormat:@"%@/%@",tutorModel.attendStudents,tutorModel.totalstudents];
//                }
//
//                label.frame = CGRectMake(X/1.8+X*3.5+W*(i-3), 10, W, 20);
//            }
//        }
//
//    }
    
    
    
    
    
    
    
    for (int i = 0; i<8; i++) {
        UILabel *label = (UILabel *)[_baseView viewWithTag:i+1];
        if (i == 0) {
            label.text = self.nameArray[i];
            label.frame = CGRectMake(0, 10, X/1.8, 20);
        }else if(i == 1){
            label.text = self.nameArray[i];
            label.frame = CGRectMake(X/1.8, 10, 1.5*X, 20);
        }else if (i == 2){
            label.text = self.nameArray[i];
            //label.frame = CGRectMake(X/1.8+X*1.5, 10, 2*X, 20);
        }else{
            if (i == 6) {
                _lookButton.frame = CGRectMake(X/1.8+X*3.5+W*(i-3)+W/2-8, 10,16, 20);
            }else if (i == 7){
                _videoButton.frame = CGRectMake(X/1.8+X*3.5+W*(i-3)+W/2-8, 10, 16, 20);
            }else{
                label.text = self.nameArray[i];
              label.frame = CGRectMake(X/1.8+X*3.5+W*(i-3), 10, W, 20);
            }
        }
        
    }
}
- (void)layout{
    
}
- (UIView *)baseView{
    if (!_baseView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        view.userInteractionEnabled = YES;
        _baseView = view;
    }
    return _baseView;
}
- (UIButton *)lookButton{
    if (!_lookButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"sx_xiaozu_chakan"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(lookButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.userInteractionEnabled = YES;
        _lookButton = button;
    }
    return _lookButton;
}
- (void)lookButtonClick:(UIButton *)sender{
    self.lookBlock(self.indexPath);
}
- (UIButton *)videoButton{
    if (!_videoButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"zy_player_zanting"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(videoButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.userInteractionEnabled = YES;
        _videoButton = button;
    }
    return _videoButton;
}
- (void)videoButtonClick:(UIButton *)sender{
    self.videoBlock(self.indexPath);
}
@end
